import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 导入动态路由
import { asyncRoutes } from './asyncRoutes'
// 静态路由数组（每个用户都可以正常访问） + 动态路由数组（需要做权限控制的路由，用户如果权限不一致能够访问到的路由页不一样）
// 静态路由不随着不同用户而发生变化，而动态路由随着用户的权限能访问的个数也不一样
// 动态路由
// const asyncRouters = [
//    // 工资管理
//   {
//     path: '/salary',
//     component: Layout,
//     children: [{
//       path: '',
//       name: 'Salary',
//       component: () => import('@/views/Salary/index'),
//       meta: { title: '工资管理', icon: 'dashboard' }
//     }]
//   },
//   // 组织架构
//   {
//     path: '/department',
//     component: Layout,
//     children: [{
//       path: '',
//       name: 'department',
//       component: () => import('@/views/Department/index'),
//       meta: { title: '组织架构', icon: 'dashboard' }
//     }]
//   },
//   // 权限点
//   {
//     path: '/permission',
//     component: Layout,
//     children: [{
//       path: '',
//       name: 'permission',
//       component: () => import('@/views/Permission/index'),
//       meta: { title: '权限点管理', icon: 'dashboard' }
//     }]
//   },
//   // 员工管理
//   {
//     path: '/employee',
//     component: Layout,
//     children: [{
//       path: '',
//       name: 'employee',
//       component: () => import('@/views/Employee/index'),
//       meta: { title: '员工管理', icon: 'dashboard' }
//     }]
//   },
//    // 角色管理
//   {
//     path: '/setting',
//     component: Layout,
//     children: [{
//       path: '',
//       name: 'setting',
//       component: () => import('@/views/Setting/index'),
//       meta: { title: '角色管理', icon: 'setting' }
//     }]
//   }

// ]
// 静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/Dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    // 左面不用显示 导入员工
    hidden: 'true',
    path: '/import',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: '',
      name: 'import',
      component: () => import('@/views/ImportExcel/index'),
      meta: { title: '导入', icon: 'dashboard' }
    }]
  },
  {
    // 左面不用显示 查看员工详情
    hidden: 'true',
    path: '/employeeDetail',
    component: Layout,
    redirect: '/employeeDetail',
    children: [{
      path: '',
      name: 'import',
      component: () => import('@/views/EmployeeDetail/index'),
      meta: { title: '员工详情'}
    }]
  },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  // mode: 'history',
  // 更改路由模式
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  // routes: constantRoutes
  // 动态路由和静态路由组合在一起
  // routes: [...constantRoutes, ...asyncRoutes]
  routes: [...constantRoutes]

})
const router = createRouter()

// reset 路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher // 重新设置路由的可匹配路径
}

export default router
